package org.jeecg.modules.power.config.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.power.config.entity.YlQuestion;
import org.jeecg.modules.power.config.mapper.YlQuestionMapper;
import org.jeecg.modules.power.config.service.IYlQuestionService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: 客服中心问答
 * @Author: jeecg-boot
 * @Date:   2024-07-05
 * @Version: V1.0
 */
@Service
public class YlQuestionServiceImpl extends ServiceImpl<YlQuestionMapper, YlQuestion> implements IYlQuestionService {

    /**
     * 获取智能问答列表数据
     * @param type
     * @return
     */
    public Map<String,List<Map<String,Object>>> getQuestionList(Integer type){
        QueryWrapper<YlQuestion> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(type!=null,"type",type);
        List<YlQuestion> pageList = this.list(queryWrapper);
        Map<Integer,List<YlQuestion>> questionList = pageList.stream().collect(Collectors.groupingBy(YlQuestion::getType));
        Map<String,List<Map<String,Object>>> listMap = new HashMap<>();
        for(Integer types:questionList.keySet()){
            List<YlQuestion> tempList = questionList.get(types);
            List<Map<String,Object>> mapList = tempList.stream().map(e->{
                Map<String,Object> res = new HashMap<>();
                res.put("title",e.getTitle());
                res.put("content",e.getContent());
                res.put("type",e.getType());
                return res;
            }).collect(Collectors.toList());
            String typeName = ""+types;
            listMap.put(typeName,mapList);
        }
        return listMap;
    }

}
